package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO;
import com.ourteam.workspace.dao.WorkspaceScmChangePathLog;
import com.ourteam.workspace.dao.WorkspaceScmChangePathLogDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:34 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceScmChangePathLogDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceScmChangePathLogDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        WorkspaceScmLogId,
        Path,
        Action,
        Copysrcrevision,
        Copysrcpath,
        Status,
        Remarks,
        WorkspaceId,
        WorkspaceScmConfigId,
        ChangeLineCount,
        LineCount,
        CommentLineCount,
        BlankLineCount,
        FileSize,
        Author,
        RevisionTime,
        Revision,
        TotalLines,
        TotalSize,
        WorkspaceName
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.WorkspaceScmLogId,
        _DataObjectProperty.Path,
        _DataObjectProperty.Action,
        _DataObjectProperty.Copysrcrevision,
        _DataObjectProperty.Copysrcpath,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.WorkspaceId,
        _DataObjectProperty.WorkspaceScmConfigId,
        _DataObjectProperty.ChangeLineCount,
        _DataObjectProperty.LineCount,
        _DataObjectProperty.CommentLineCount,
        _DataObjectProperty.BlankLineCount,
        _DataObjectProperty.FileSize,
        _DataObjectProperty.Author,
        _DataObjectProperty.RevisionTime,
        _DataObjectProperty.Revision,
        _DataObjectProperty.TotalLines,
        _DataObjectProperty.TotalSize,
        _DataObjectProperty.WorkspaceName
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<WorkspaceScmChangePathLog, WorkspaceScmChangePathLogDAOQueryBean>
      daoHelper;

  public AbstractWorkspaceScmChangePathLogDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<
            WorkspaceScmChangePathLog, WorkspaceScmChangePathLogDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.workspace.dao.IWorkspaceScmLogDAO.EntityName)
          .append(" SCM_CHANGE_LOG ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.workspace.dao.IWorkspaceScmLogDAO.Id,
              com.ourteam.workspace.dao.IWorkspaceScmLogDAO.EntityName + ".",
              "SCM_CHANGE_LOG."));
      relatedJoinSQLBuffer.append(" = ").append(WorkspaceScmLogId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.workspace.dao.IWorkspaceDAO.EntityName)
          .append(" WORKSPACE ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.workspace.dao.IWorkspaceDAO.Id,
              com.ourteam.workspace.dao.IWorkspaceDAO.EntityName + ".",
              "WORKSPACE."));
      relatedJoinSQLBuffer.append(" = ").append(WorkspaceId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceScmChangePathLog
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceScmChangePathLog aWorkspaceScmChangePathLog)
      throws Exception {

    if (aWorkspaceScmChangePathLog == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceScmChangePathLog.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceScmChangePathLog
   * @throws Exception
   */
  public void insert(WorkspaceScmChangePathLog aWorkspaceScmChangePathLog) throws Exception {

    super.doInsert(aWorkspaceScmChangePathLog);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceScmChangePathLog
   * @throws Exception
   */
  public void batchInsert(WorkspaceScmChangePathLog[] aWorkspaceScmChangePathLogs)
      throws Exception {

    super.doBatchInsert(aWorkspaceScmChangePathLogs);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceScmChangePathLogDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceScmChangePathLog aWorkspaceScmChangePathLog) throws Exception {

    delete(aWorkspaceScmChangePathLog.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceScmChangePathLog
   * @throws Exception
   */
  public void update(WorkspaceScmChangePathLog aWorkspaceScmChangePathLog) throws Exception {

    if (aWorkspaceScmChangePathLog.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceScmChangePathLog);

    WorkspaceScmChangePathLog tempObj = findById(aWorkspaceScmChangePathLog.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceScmChangePathLog, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceScmChangePathLogs[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceScmChangePathLog[] aWorkspaceScmChangePathLogs)
      throws Exception {

    super.doBatchUpdate(aWorkspaceScmChangePathLogs);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceScmChangePathLog
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      WorkspaceScmChangePathLog aWorkspaceScmChangePathLog,
      WorkspaceScmChangePathLogDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceScmChangePathLog, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceScmChangePathLogDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceScmChangePathLog aWorkspaceScmChangePathLog)
      throws Exception {

    if (aWorkspaceScmChangePathLog.getPath() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.path value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getAction() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.action value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getCopysrcrevision() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.copysrcrevision value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getCopysrcpath() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.copysrcpath value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getStatus() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.status value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getRemarks() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.remarks value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getAuthor() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.author value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getRevisionTime() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.revisionTime value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getRevision() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.revision value is not allow NULL");
    }

    if (aWorkspaceScmChangePathLog.getWorkspaceName() == null) {
      throw new Exception("The WorkspaceScmChangePathLog.workspaceName value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceScmChangePathLog findById(final long id) throws Exception {

    WorkspaceScmChangePathLogDAOQueryBean queryBean = new WorkspaceScmChangePathLogDAOQueryBean();

    WorkspaceScmChangePathLogDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceScmChangePathLog[] WorkspaceScmChangePathLogs = query(queryBean);

    if (WorkspaceScmChangePathLogs.length == 0) {
      return null;
    } else {
      return WorkspaceScmChangePathLogs[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceScmChangePathLog[]
   * @throws Exception
   */
  public WorkspaceScmChangePathLog[] query(WorkspaceScmChangePathLogDAOQueryBean queryBean)
      throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceScmChangePathLogRowMapper());

    return (WorkspaceScmChangePathLog[])
        result.toArray(new WorkspaceScmChangePathLog[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceScmChangePathLogDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceScmChangePathLogDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceScmChangePathLog[] aWorkspaceScmChangePathLogs,
      WorkspaceScmChangePathLogDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aWorkspaceScmChangePathLogs, queryBean);
  }

  public void synchronize(
      WorkspaceScmChangePathLog[] aWorkspaceScmChangePathLogs,
      WorkspaceScmChangePathLogDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceScmChangePathLog> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceScmChangePathLogs, queryBean, callBack);
  }

  public static class JdbcWorkspaceScmChangePathLogRowMapper
      implements RowMapper<WorkspaceScmChangePathLog> {

    public WorkspaceScmChangePathLog mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceScmChangePathLog object = new WorkspaceScmChangePathLog();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object workspaceScmLogId = null;

        workspaceScmLogId = resultSet.getObject(columnIndex++);

        object.setWorkspaceScmLogIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceScmLogId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceScmLogId, workspaceScmLogId);
        }

        Object path = null;

        path = resultSet.getObject(columnIndex++);

        object.setPathNull(resultSet.getBoolean(columnIndex++));

        if (path != null) {

          setBeanValue(object, _DataObjectProperty.Path, path);
        }

        Object action = null;

        action = resultSet.getObject(columnIndex++);

        object.setActionNull(resultSet.getBoolean(columnIndex++));

        if (action != null) {

          setBeanValue(object, _DataObjectProperty.Action, action);
        }

        Object copysrcrevision = null;

        copysrcrevision = resultSet.getObject(columnIndex++);

        object.setCopysrcrevisionNull(resultSet.getBoolean(columnIndex++));

        if (copysrcrevision != null) {

          setBeanValue(object, _DataObjectProperty.Copysrcrevision, copysrcrevision);
        }

        Object copysrcpath = null;

        copysrcpath = resultSet.getObject(columnIndex++);

        object.setCopysrcpathNull(resultSet.getBoolean(columnIndex++));

        if (copysrcpath != null) {

          setBeanValue(object, _DataObjectProperty.Copysrcpath, copysrcpath);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object workspaceId = null;

        workspaceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceId, workspaceId);
        }

        Object workspaceScmConfigId = null;

        workspaceScmConfigId = resultSet.getObject(columnIndex++);

        object.setWorkspaceScmConfigIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceScmConfigId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceScmConfigId, workspaceScmConfigId);
        }

        Object changeLineCount = null;

        changeLineCount = resultSet.getObject(columnIndex++);

        object.setChangeLineCountNull(resultSet.getBoolean(columnIndex++));

        if (changeLineCount != null) {

          setBeanValue(object, _DataObjectProperty.ChangeLineCount, changeLineCount);
        }

        Object lineCount = null;

        lineCount = resultSet.getObject(columnIndex++);

        object.setLineCountNull(resultSet.getBoolean(columnIndex++));

        if (lineCount != null) {

          setBeanValue(object, _DataObjectProperty.LineCount, lineCount);
        }

        Object commentLineCount = null;

        commentLineCount = resultSet.getObject(columnIndex++);

        object.setCommentLineCountNull(resultSet.getBoolean(columnIndex++));

        if (commentLineCount != null) {

          setBeanValue(object, _DataObjectProperty.CommentLineCount, commentLineCount);
        }

        Object blankLineCount = null;

        blankLineCount = resultSet.getObject(columnIndex++);

        object.setBlankLineCountNull(resultSet.getBoolean(columnIndex++));

        if (blankLineCount != null) {

          setBeanValue(object, _DataObjectProperty.BlankLineCount, blankLineCount);
        }

        Object fileSize = null;

        fileSize = resultSet.getObject(columnIndex++);

        object.setFileSizeNull(resultSet.getBoolean(columnIndex++));

        if (fileSize != null) {

          setBeanValue(object, _DataObjectProperty.FileSize, fileSize);
        }

        Object author = null;

        author = resultSet.getObject(columnIndex++);

        object.setAuthorNull(resultSet.getBoolean(columnIndex++));

        if (author != null) {

          setBeanValue(object, _DataObjectProperty.Author, author);
        }

        Object revisionTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          revisionTime = resultSet.getTimestamp(columnIndex++);

        } else {
          revisionTime = resultSet.getObject(columnIndex++);
        }

        object.setRevisionTimeNull(resultSet.getBoolean(columnIndex++));

        if (revisionTime != null) {

          setBeanValue(object, _DataObjectProperty.RevisionTime, revisionTime);
        }

        Object revision = null;

        revision = resultSet.getObject(columnIndex++);

        object.setRevisionNull(resultSet.getBoolean(columnIndex++));

        if (revision != null) {

          setBeanValue(object, _DataObjectProperty.Revision, revision);
        }

        Object totalLines = null;

        totalLines = resultSet.getObject(columnIndex++);

        object.setTotalLinesNull(resultSet.getBoolean(columnIndex++));

        if (totalLines != null) {

          setBeanValue(object, _DataObjectProperty.TotalLines, totalLines);
        }

        Object totalSize = null;

        totalSize = resultSet.getObject(columnIndex++);

        object.setTotalSizeNull(resultSet.getBoolean(columnIndex++));

        if (totalSize != null) {

          setBeanValue(object, _DataObjectProperty.TotalSize, totalSize);
        }

        Object workspaceName = null;

        workspaceName = resultSet.getObject(columnIndex++);

        object.setWorkspaceNameNull(resultSet.getBoolean(columnIndex++));

        if (workspaceName != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceName, workspaceName);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
